﻿using System;
using System.Data;
using System.Web;
using Telerik.Web.UI;
using KPIS.GERP.GIMS.DAL;
using KPIS.GERP.GIMS.MODEL;

namespace KPIS.GERP.GIMS.APP.APP_UI.Common
{
    public class Main
    {
        D_Employee d_employee = new D_Employee();
        M_Employee m_employee = new M_Employee();

        #region UserSystem
            public Int32 UserID = 1 ;//
            public Int32 ApproveID = 60;
        
            public string EmployeeName()
            {
                M_Employee info = d_employee.GetListFillBySeq(UserID);
                return info.emp_name;
            }
            public string OrganizeName()
            {
                M_Employee info = d_employee.GetListFillBySeq(UserID);
                return info.job_site_name;
            }
            public Nullable<Int32> JobsiteSeq()
            {
                M_Employee info = d_employee.GetListFillBySeq(UserID);
                return info.job_site_seq;
            }
            public string EmployeePositionName()
            {
                M_Employee infohavepos_app = d_employee.GetListApproveFillBySeq(UserID);
                return infohavepos_app.emp_position;
            }
            public Nullable<Int32> ApproveSeq()
            {
                M_Employee infohavepos_app = d_employee.GetListApproveFillBySeq(UserID);
                return infohavepos_app.app_seq;
            }
            public string ApproveName()
            {
                M_Employee infohavepos_app = d_employee.GetListApproveFillBySeq(UserID);
                return infohavepos_app.app_name;
            }
            public string ApprovePositionName()
            {
                M_Employee infohavepos_app = d_employee.GetListApproveFillBySeq(UserID);
                return infohavepos_app.app_position;
            }
        #endregion

        #region convert object
           public Nullable<int> ConvertNullInt(Object o)
            {
                Nullable<int> result = (o == null ? null : (o.ToString().Length == 0 ? null : (Nullable<int>)Convert.ToInt32(o)));
                return result;
            }

            public Nullable<double> ConvertNullDouble(Object o)
            {
                Nullable<double> result = (o == null ? null : (o.ToString().Length == 0 ? null : (Nullable<double>)Convert.ToDouble(o)));
                return result;
            }

            public Nullable<DateTime> ConvertNullDateTime(Object o)
            {
                Nullable<DateTime> result = (o == null ? null : (o.ToString().Length == 0 ? null : (Nullable<DateTime>)Convert.ToDateTime(o)));
                return result;
            }
            public Nullable<Boolean> ConvertNullBoolean(Object o)
            {
                Nullable<Boolean> result = (o == null ? null : (o.ToString().Length == 0 ? null : (Nullable<Boolean>)Convert.ToBoolean(o)));
                return result;
            }
        #endregion

            #region Convert Date
            public string ConvertstrMonth(string pMonth)
            {
                string strMonth = "";
                if (pMonth.Length < 2)
                    strMonth = "0" + pMonth;
                else
                    strMonth = pMonth;
                return strMonth;
            }
            public string ConvertstrRunningThreeDigit(string pRunning)
            {
                string strRunning = "";
                if (pRunning.Length < 1)
                    strRunning = "000";
                else if (pRunning.Length < 2)
                    strRunning = "00" + pRunning;
                else if (pRunning.Length < 3)
                    strRunning = "0" + pRunning;
                else
                    strRunning = pRunning;
                return strRunning;
            }
            public string ConvertstrRunningFiveDigit(string pRunning)
            {
                string strRunning = "";
                if (pRunning.Length < 1)
                    strRunning = "00000";
                else if (pRunning.Length < 2)
                    strRunning = "0000" + pRunning;
                else if (pRunning.Length < 3)
                    strRunning = "000" + pRunning;
                else if (pRunning.Length < 4)
                    strRunning = "00" + pRunning;
                else if (pRunning.Length < 5)
                    strRunning = "0" + pRunning;
                else
                    strRunning = pRunning;
                return strRunning;
            }
            public string ConvertStrToStrDate(string pstrDate)
            {
                string day = "";
                string month = "";
                string year = "";
                string strDate = "";
                string[] all_date = pstrDate.ToString().Split('/');
                if (pstrDate != null)
                {
                    all_date = pstrDate.ToString().Split('/');
                    if (all_date[0].Length > 0)
                    {
                        if (all_date[0].Length < 2)
                        {
                            day = "0" + all_date[0];
                        }
                        else
                        {
                            day = all_date[0];
                        }
                        if (all_date[1].Length < 2)
                        {
                            month = "0" + all_date[1];
                        }
                        else
                        {
                            month = all_date[1];
                        }

                        year = all_date[2];
                        strDate = day + "/" + month + "/" + year;
                    }
                }
                return strDate;
            }

            #endregion

            #region ShowStatus
            public string GetStatusMessage(int offset, int total)
            {
                if (total <= 0)
                    return "ไม่พบข้อมูล";

                return String.Format("ลำดับที่ <b>1</b>-<b>{0}</b> จากทั้งหมด <b>{1}</b>", offset, total);
            }
        #endregion

        #region "Other"
            public void UpdateTabStrip(RadTabStrip tab, int nSelectIndex, string strMode)
            {
                if (strMode == "AddNew")
                {
                    for (int i = 0; i < tab.Tabs.Count; i++)
                    {
                        tab.Tabs[i].Enabled = i <= nSelectIndex;
                    }
                }
                else
                {
                    for (int i = 0; i < tab.Tabs.Count; i++)
                    {
                        tab.Tabs[i].Enabled = true;
                    }
                }
            }
#endregion

    }
}
